package it.softphone.commons.json.server.converter;


import it.softphone.commons.json.server.JSONConverter;
import it.softphone.commons.json.server.JSONObject;

import java.util.Date;


public class JSONDateConverter implements JSONConverter<java.util.Date> {

	public Object convert(Date value) {
		
		return (value == null) ? JSONObject.NULL : value.getTime();

	}

	@SuppressWarnings("rawtypes")
	public Object convert(Class type, Object value) {
		
		if( JSONObject.NULL==value || null==value) return null;
		
		if( value instanceof Long ) {
			return new java.util.Date( (Long)value );
		}
		if( value.getClass().isInstance(Long.TYPE)) {
			return new java.util.Date( (Long)value );
		}
		
		return value;
	}
	
}
